package com.bsoft.utils;

import com.bsoft.Exception.CommonException;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Map;

public class DateUtil {

    public static Date parseDateTime(String dateStr) {
        if (dateStr == null) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date =null;
        try {
             date = formatter.parse(dateStr); // 将字符串解析为 Date 对象
        } catch (ParseException e) {
            System.out.println("日期格式错误: " + e.getMessage());
        }

        return date;
    }

    /**
     * 平台时间处理
     */
    public static void stringToDatePt(Map<String, Object> req, String strDate, String format) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format.replace("T",""));
        try {
            Date date = dateFormat.parse(req.get(strDate).toString().replace("T",""));
            req.put(strDate, date);
        } catch (ParseException e) {
            throw new CommonException("传入" + strDate + "时间格式错误不是"+format);
        }

    }


    //判断当天日期和传的日期是否相等
    public static boolean eqStrTime( String time) {
        String format = cn.hutool.core.date.DateUtil.format(new Date(), "yyyy-MM-dd");
        return time.equals(format);
    }

}
